package com.cci.kangdao.task;

import com.cci.kangdao.crmapi.CRMApiUtils;
import com.cci.kangdao.crmapi.CRMResponeEntity;
import com.cci.kangdao.dao.CRMPlatformServiceDao;
import com.cci.kangdao.redis.RedisClientUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * @description: 处理
 * @author: shiliqiang
 * @company: CTY Technology Co.,Ltd
 * @since: 2021/11/18 13:33
 * @version: V1.0
 */
public class ThreadTask implements Runnable{
    private Logger log = Logger.getLogger(this.getClass().getName());

    private Map<String, Object> map;

    private CRMPlatformServiceDao platformServiceDao;

    private RedisClientUtils redisClientUtils;

    private Map<String,Object> crmMap;
    public ThreadTask(Map<String, Object> map, CRMPlatformServiceDao platformServiceDao, RedisClientUtils redisClientUtils, Map<String,Object> crmMap) {
        this.map = map;
        this.platformServiceDao = platformServiceDao;
        this.redisClientUtils = redisClientUtils;
        this.crmMap = crmMap;
    }

    @Override
    public void run() {
        try {
            crmMap.put("OrderId", MapUtils.getIntValue(map,"OrderId",-1));
            crmMap.put("IMEI",MapUtils.getString(map,"IMEI",""));
            crmMap.put("LocLon",MapUtils.getString(map,"LocLon",""));
            crmMap.put("LocLat",MapUtils.getString(map,"LocLat",""));
            crmMap.put("ProLocation",MapUtils.getString(map,"ProLocation",""));
            CRMResponeEntity CRMres = CRMApiUtils.getCRMServiceApi().syncAppOrderInfoToCRM(map.get("OrderChannelName").toString(),platformServiceDao,redisClientUtils,crmMap,null);
            if(CRMres.getStatus() != 0) {
                // APP同步工单信息到CRM系统失败
                /**
                 * 注释log
                 * 20230808
                 * sxt 处理Privacy Violation
                 */
                //log.error("服务站APP在线报修同步工单信息至CRM失败，状态："+CRMres.getStatus()+"，用户信息:"+CRMres.getMessage());
                log.error("服务站APP在线报修同步工单信息至CRM失败，状态："+CRMres.getStatus());
            }
        } catch (Exception e) {
            //APP同步工单信息到CRM系统失败
            log.error("服务站APP在线报修同步工单信息至CRM失败："+e.getMessage(),e);
        }
    }
}
